package com.whsxt.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.whsxt.sys.domain.Dept;
import com.whsxt.sys.domain.User;
import com.whsxt.sys.mapper.DeptMapper;
import com.whsxt.sys.mapper.UserMapper;

public class CachePool {
	
	public static volatile Map<String, Object> map = new HashMap<String, Object>();
	
	/**
	 * 根据key 删除缓存
	 */
	public static void removeCacheByKey(String key) {
		if(map.containsKey(key)) {
			map.remove(key);
		}
		
	}
	/**
	 *  清除所有缓存
	 */
	public static void removeAll() {
		map.clear();
	}
	
	/**
	 *  同步所有缓存
	 */
	public static void syncAll() {
		UserMapper bean = SpringUtil.getBean(UserMapper.class);	
		List<User> list = bean.selectList(null);
		for (User user : list) {
			map.put("user"+user.getId(), user);
		}
		DeptMapper bean2 = SpringUtil.getBean(DeptMapper.class);	
		List<Dept> list2 = bean2.selectList(null);
		for (Dept dept : list2) {
			map.put("dept"+dept.getId(), dept);
		}
	}
	
}
